﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Algoritmia.Problems.ActivitySelection
{
    public class ActivitiesSelector1 : IActivitiesSelector
    {
        #region Implementation of IActivitiesSelector

        public IEnumerable<Tuple<double, double>> Select(IEnumerable<Tuple<double, double>> activities)
        {
            var x = new List<Tuple<double, double>>();
            var activitiesList = activities.ToList();
            activitiesList.Sort((tp1, tp2) => tp1.Item2.CompareTo(tp2.Item2)); 
            foreach(var activity in activitiesList)
            {
                var a = activity;
                if ( !x.Any(e => (e.Item1 >= a.Item1 && a.Item1 < e.Item2) ||
                                 (e.Item1 > a.Item2 && a.Item2 <= e.Item2)   ) )
                {
                    x.Add(a);
                }
            }
            return x;
        }

        #endregion
    }
}
